﻿using UnityEngine;
using System.Collections;

public class Cell : MonoBehaviour {
	public BoardManager boardMng;
	public float curSec;
	public bool playFillAnim=false;
	public bool isClicked=false;
	public int myID;
	public int myLineID;
	public int curColor=0; /// <summary>
	/// -1 black,0 nothing, 1 white
	/// </summary>
	// Use this for initialization
	void Awake(){
		boardMng=FindObjectOfType<BoardManager>();

	}
	void Start () {
	}
	
	// Update is called once per frame
	void Update () {
		if(playFillAnim){

			GetComponent<UISprite>().fillAmount=(float)(1.0/2)*curSec;
			curSec+=Time.deltaTime;
			if(GetComponent<UISprite>().fillAmount==1){
				curSec=0;
				playFillAnim=false;
			}
		}

	}

	void isClick(){
		if(!isClicked)
		{
			isClicked=true;
			Vector2 tmp=new Vector2(myLineID,myID);//lưu lại vị trí đã click
			BoardManager.curID=tmp;
			if(curColor==0){
				if(BoardManager.curTurn==TURN.HUMAN)
				{
					curColor=-1; //sau này khi có player thì màu sẽ tùy vào player nào
					BoardManager.lastValue=-1;//lưu màu cờ vừa đánh xuống
				}
				else{
					curColor=1;
					BoardManager.lastValue=1;
				}

			};
			BoardManager.isClick=true;
		}

		
	}
	public void updateSprite(){
		if(curColor==-1){
			GetComponent<UISprite>().spriteName="black";
		}
		else{
			GetComponent<UISprite>().spriteName="white";
		}
	}
}
